
 import excel "Election_data_with_county.xlsx",  sheet("Sheet1") firstrow

*Removal of non-far-left candidates*
keep if pty==7 | pty==23 | pty==25


*Checking and removal of duplicates (instances of more than one candidates), since we are only interested in party-level data*
sort id cst
by id cst:  gen dup = cond(_N==1,0,_n)
list cst_n yr if dup>0


*Setting uncontested elections and missing data for relevant variables to missing*
destring pev1 vot1 vv1 pv1, replace force


*Appending communist electoral data*
append using "1920_1935_election_communists.dta"


*Collapsing by county and election*

collapse (sum) pev1 vot1 vv1 pv1 (mean) yr, by( county id)







*Merging of population data*

merge m:1 county yr using "populationdata2.dta"

drop _merge
*Merging with Terror data*

merge m:1 county using "\german_terror.dta"


*Generation of numeric county variable*
encode county, gen(county_n)



*Generation of log of population*
generate logpop= log(pop_total)

*generate urbanization*
 generate urbanization= pop_city /pop_total
generate ruralshare= pop_rural /pop_total
 
 
*setting time frame*
xtset county_n id



*Generation of a turnout variable*
generate n_votes= vv1
replace n_votes= vot1 if vv1==0
replace n_votes=. if vot1==0 & vv1==0 

generate turnout= n_votes/pev1 



*Generation of  measure of  electoral support (share of votes)*
generate communistsfsupport= pv1/n_votes


*Generation of Terror index*
generate repressionindex2= number_killed+ number_attempted_killed/2+ wounded/2 +damages_dkk/1000000




generate postwar=0
replace postwar=1 if yr>1944

generate placebo=0
replace placebo=1 if yr>1938 


*Figure 6: Difference-in-difference war-terror*

xtset county_n id

generate newyr= 2000-yr




xtreg  communistsfsupport i.newyr#c.repressionindex2 urbanization logpop  i.id, fe cluster (county_n)
margins, dydx(repressionindex2 ) over (i.newyr) noestimcheck
marginsplot, level(90)xtitle (Year) ytitle (Effect of German Terror on far-left vote share) yline(0, lstyle(grid) lcolor(gs8) lpattern(dash))graphregion(color(white))legend (off) scheme(s2mono) recastci(rline) recast(line) title("") xlabel(, format(%9.0f)) ylabel(, format(%9.4f)) xlabel( 80 "1920" 74 "1926" 68 "1932" 61 "1939"  55 "1945"  50 "1953" 43 "1957" 36 "1964"  29 "1971", format(%9.0f))  xline(60, lstyle(grid) lcolor(gs8) lpattern(longdash))xline(42, lstyle(grid) lcolor(gs8) lpattern(solid))  xscale(reverse)

